<?php
@header('Content-type: text/html;charset=UTF-8');
require_once('ly_check.php');
?>
<?php
if ($_POST["Submit"]) {
    $commodityId = str_replace(' ','',$_POST["commodityId"]);
    $commodityName = str_replace(' ','',$_POST["commodityName"]);
    $flag = $_POST["flag"];
    $sql = "select * from commodity where commodityId='$commodityId'";
    $rs = mysql_query($sql);
    if (mysql_num_rows($rs) == 1) {
        echo "<script language=javascript>alert('商品编码已存在！');history.back();</script>";
    } else {
        $sql = "insert into commodity (commodityId,commodityName,flag) values ($commodityId,'$commodityName','$flag')";
        mysql_query($sql);
        echo "<script language=javascript>alert('添加成功！');window.location='index.php?pageno=$pageno'</script>";
    }
}
?>
<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>商品添加</title>
    <link rel="stylesheet" href="../images/css.css" type="text/css"/>
    <script type="text/javascript">
        function check() {
            var commodityId = document.getElementById("commodityId");
            var commodityName = document.getElementById("commodityName");
            if (trim(commodityId.value) == null || trim(commodityId.value) == "") {
                alert("请输入商品编码");
                commodityId.focus();
                return false;
            }
            if (isNaN(trim(commodityId.value))) {
                alert("商品编码必须是数字");
                serviceStationId.focus();
                return false;
            }
            if (trim(commodityName.value) == null || trim(commodityName.value) == "") {
                alert("请输入商品名称");
                commodityName.focus();
                return false;
            }
            return true;
        }
        function trim(str) { //删除左右两端的空格
            return str.replace(/(^\s*)|(\s*$)/g, "");
        }
    </script>
</head>
<form id="form1" name="form1" method="post" action="" onsubmit="return check();">
    <table width="100%" border="0" align="center" cellpadding="5" cellspacing="1" bordercolor="#000000"
           bgcolor="#cccccc">
        <tr>
            <th colspan="2" bgcolor="#FFFFFF">添加商品</th>
        </tr>
        <tr>
            <td bgcolor="#FFFFFF" class="forumRowHighlight">商品编号:</td>
            <td bgcolor="#FFFFFF" class="forumRowHighlight"><input type="text" name="commodityId" id="commodityId"/>*
            </td>
        </tr>
        <tr>
            <td bgcolor="#FFFFFF" class="forumRowHighlight">商品名称:</td>
            <td bgcolor="#FFFFFF" class="forumRowHighlight"><input type="text" name="commodityName" id="commodityName"/>*
            </td>
        </tr>
        <tr>
            <td bgcolor="#FFFFFF" class="forumRowHighlight">商品标志:</td>
            <td bgcolor="#FFFFFF" class="forumRowHighlight">
                <select id="flag" name="flag">
                    <option value="1">代买</option>
                    <option value="2">代卖</option>
                </select>
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center"><input name="Submit" type="submit" class="button" value="提交"/>
                &nbsp;
                <input name="Submit2" type="reset" class="button" value="重置"/></td>
        </tr>
    </table>
</form>
</body>
</html>